package org.example.exception.handler;

import org.example.exception.AuthApiException;
import org.example.exception.DefaultApiException;
import org.example.util.JsonBody;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class DefaultControllerExceptionHandler {

    @ExceptionHandler
    public JsonBody defaultApiExceptionHandler(DefaultApiException e) {
        return JsonBody.error(e.getLocalizedMessage());
    }

    @ExceptionHandler
    public JsonBody authApiExceptionHandler(AuthApiException e) {
        return JsonBody.custom(JsonBody.Codes.AUTH_ERROR, e.getLocalizedMessage());
    }
}
